package com.bins.uaa.auth.controller;

import com.bins.auth.api.controller.AuthApi;
import com.bins.auth.api.dto.LoginDto;
import com.bins.auth.api.dto.UserDto;
import com.bins.auth.api.vo.AuthToken;
import com.bins.auth.api.vo.JwtResult;
import com.bins.auth.api.vo.LoginVo;
import com.bins.uaa.auth.service.AuthService;
import com.bins.uaa.common.constants.CommonCode;
import com.bins.uaa.common.constants.ResponseBody;
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
@RequestMapping("/")
public class AuthController implements AuthApi {

//    @Value("${auth.clientId}")
//    String clientId;
//    @Value("${auth.clientSecret}")
//    String clientSecret;
//    @Value("${auth.cookieDomain}")
//    String cookieDomain;
//    @Value("${auth.cookieMaxAge}")
//    int cookieMaxAge;
//
//    @Autowired
//    AuthService authService;

    @Override
    @PostMapping("/user/login")
    public LoginVo login(LoginDto loginDto) {
//        String username = loginDto.getUsername();
//        String password = loginDto.getPassword();
//        AuthToken authToken = authService.login(username,password,clientId,clientSecret);
//        String access_token = authToken.getAccess_token();
        String access_token = UUID.randomUUID().toString();
        return new LoginVo(CommonCode.SUCCESS,access_token);
    }

    @Override
    @PostMapping("/user/logout")
    public ResponseBody logout(UserDto dto) {
//        Long userId = dto.getId();
//        boolean result = authService.delToken(userId);
        return new ResponseBody(CommonCode.SUCCESS);
    }

    @Override
    @GetMapping("/user/jwt")
    public JwtResult userJwt(UserDto dto) {
//        Long userId = dto.getId();
//        if(userId == null || userId == 0){
//            return new JwtResult(CommonCode.FAIL,null);
//        }
//        AuthToken userToken = authService.getUserToken(userId);
//        if(userToken!=null){
//            String jwt_token = userToken.getJwt_token();
//            return new JwtResult(CommonCode.SUCCESS,jwt_token);
//        }
        return null;
    }

    @GetMapping
    public String findAll() {
        return "查询所有用户成功！";
    }
}
